package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface UserMapper {
    //1. 用户列表查询
    List<User> selectList(UserDto userDto);
    //3. 添加用户
    @Insert("insert into user(username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time) value (#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void insert(User user);
    //2. 删除用户
    void deleteByIds(List<Integer> ids);
     //4. 根据ID查询
    @Select("select id,username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time from user where id = #{id}")
    User selectById(Integer id);
    //5. 修改用户
    void update(User user);
    //6. 查询所有用户
    @Select("select id,username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time from user")
    List<User> list();
    //7. 根据角色查询用户
    @Select("select * from user ,role  where user.role_id = role.id and status =1 and  role.label = #{roleLabel} ")
    List<User> listByRole(String roleLabel);
    //8. 根据部门查询用户
    @Select("select * from user where status =1 and  dept_id = #{deptId} ")
    List<User> listByDept(Integer deptId);
    //登录
    @Select("select u.*, r.label as role_label from user u left join role r on u.role_id = r.id where username = #{username}")
    User selectByUsername(String username);
}
